**************************************************************
*
* Replication file for "Unlocking public support"
*
* Foreign Policy Analysis
* Contact: Bernhard.Reinsberg@glasgow.ac.uk
*
**************************************************************

* Data and variables
********************

  use "Gallup data", clear

  ** the data can be downloaded from this URL: 
  ** https://doi.org/10.7910/DVN/YAM0WX 

  
* Key treatments

  des hurt adjburden socprog  
  
  lab var hurt "hurt"
  lab var adjburden "adjburden"
  lab var socprog "socprog"
  
  
* Outcomes

  g prog_app=q3==3|q3==4
  lab var prog_app "Program support"
  g confimf=q6
  lab var confimf "Confidence in the IMF"

  
* Covariates

  g knowimf=q9==1
  lab var knowimf "Knowledgeable about the IMF"
  g male=d1==1
  lab var male "Male"
  g age=d2 
  lab var age "Age"
  g edulevel=d3 if d3<10
  lab var edulevel "Education"
  g ftemp=d4==1
  lab var ftemp "Employed"
  g psj=d4a==1
  lab var psj "Public-sector"
  g urb=d5==1
  lab var urb "Urban"
  g inclevel=d7
  lab var inclevel "Income"
  g language=d8
  lab var language "Language"
 
  global X1 male age edulevel inclevel urb
  global X2 ftemp psj i.language 


* Main analysis 
***************

* IMF design primes and support for IMF program

  ** Figure 1
  qui reg prog_app i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame [pw = Weight] if q9==1
  coefplot, keep(*hurt *adjburden *socprog) xline(0, lwidth(0.2) lpattern(dash)) scheme(s1mono) ytitle() xtitle() legend(off) level(90 90)

  ** Figure A3
  margins i.hurt i.adjburden i.socprog, atmeans post 
  coefplot, keep(*hurt *adjburden *socprog)  scheme(s1mono) ytitle() xtitle() legend(off) level(90 90)

  ** Figure 2
  reg confimf i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame [pw = Weight] if q9==1
  coefplot, keep(*hurt *adjburden *socprog) xline(0, lwidth(0.2) lpattern(dash)) scheme(s1mono) ytitle() xtitle() legend(off) level(90 90)
 
  ** Figure A4
  margins i.hurt i.adjburden i.socprog, atmeans post 
  coefplot, keep(*hurt *adjburden *socprog)  scheme(s1mono) ytitle() xtitle() legend(off) level(90 90)


* Robustness test with demographics 

  qui reg prog_app i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame $X1 [pw = Weight] if q9==1
  est store c11
  qui reg prog_app i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame $X1 $X2 [pw = Weight]  if q9==1
  est store c12

  qui reg confimf i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame $X1 [pw = Weight] if q9==1
  est store c13
  qui reg confimf i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame $X1 $X2 [pw = Weight] if q9==1
  est store c14

  ** Table A2
  estout c1*, drop(_* *0.* *blame) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 	

  
* Robustness test with logit 

  qui logit prog_app hurt adjburden socprog govblame industryblame ngoblame [pw = Weight] if q9==1
  est store c21
  qui logit prog_app hurt adjburden socprog govblame industryblame ngoblame $X1 [pw = Weight] if q9==1
  est store c22
  qui xi:logit prog_app hurt adjburden socprog govblame industryblame ngoblame $X1 ftemp psj i.language [pw = Weight] if q9==1
  est store c23
 
  ** Table A3 
  estout c2*, drop(_* *blame) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 	 
  

* Robustness test with ordered logit 

  ** ssc install gologit2
  qui gologit2 q3 hurt adjburden socprog govblame industryblame ngoblame [pw = Weight] if q9==1
  est store c31
  qui gologit2 q3 hurt adjburden socprog govblame industryblame ngoblame $X1 [pw = Weight] if q9==1
  est store c32
  qui xi:gologit2 q3 hurt adjburden socprog govblame industryblame ngoblame $X1 ftemp psj i.language [pw = Weight] if q9==1
  est store c33
 
  ** Table A4 
  estout c3*, drop(_* *blame) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 	 
  
  
* Robustness test with all individuals

  qui reg prog_app i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame [pw = Weight]
  est store c41
  qui reg prog_app i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame $X1 $X2 [pw = Weight]
  est store c42

  qui reg confimf i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame [pw = Weight] 
  est store c43
  qui reg confimf i.hurt i.adjburden i.socprog i.govblame i.industryblame i.ngoblame $X1 $X2 [pw = Weight]
  est store c44

  ** Table A5
  estout c4*, drop(_* *0.* *blame) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 	


* Demographics that predict screening outcome 

  tab q9
  
  g highed=edulevel>3
  g rich=inclevel>6
  g older=age>33
  
  mat M=J(7,4,0)
  
  ttest knowimf, by(highed) une
    mat M[1,1]=`r(mu_2)'
	mat M[1,2]=`r(mu_1)'
	mat M[1,3]=`r(mu_2)'-`r(mu_1)'
	mat M[1,4]=`r(p)'
  qui ttest knowimf, by(rich) une
    mat M[2,1]=`r(mu_2)'
	mat M[2,2]=`r(mu_1)'
	mat M[2,3]=`r(mu_2)'-`r(mu_1)'
	mat M[2,4]=`r(p)'
  qui ttest knowimf, by(urb) une
    mat M[3,1]=`r(mu_2)'
	mat M[3,2]=`r(mu_1)'
	mat M[3,3]=`r(mu_2)'-`r(mu_1)'
	mat M[3,4]=`r(p)'
  qui ttest knowimf, by(ftemp) une
    mat M[4,1]=`r(mu_2)'
	mat M[4,2]=`r(mu_1)'
	mat M[4,3]=`r(mu_2)'-`r(mu_1)'
	mat M[4,4]=`r(p)'
  qui ttest knowimf, by(psj) une
    mat M[5,1]=`r(mu_2)'
	mat M[5,2]=`r(mu_1)'
	mat M[5,3]=`r(mu_2)'-`r(mu_1)'
	mat M[5,4]=`r(p)'
  qui ttest knowimf, by(male) une
    mat M[6,1]=`r(mu_2)'
	mat M[6,2]=`r(mu_1)'
	mat M[6,3]=`r(mu_2)'-`r(mu_1)'
	mat M[6,4]=`r(p)'
  qui ttest knowimf, by(older) une
    mat M[7,1]=`r(mu_2)'
	mat M[7,2]=`r(mu_1)'
	mat M[7,3]=`r(mu_2)'-`r(mu_1)'
	mat M[7,4]=`r(p)'

	mat li M

  
* Heterogeneous effects

  local t=1
  foreach x in highed rich urb older ftemp male {
  
    g x=`x'
    qui reg prog_app i.hurt##i.x i.adjburden##i.x i.socprog##i.x i.govblame##i.x i.industryblame##i.x i.ngoblame##i.x [pw = Weight] if q9==1
	qui margins x, dydx(hurt adjburden socprog) post
	est store c5`t'
    
	qui reg confimf i.hurt##i.x i.adjburden##i.x i.socprog##i.x i.govblame##i.x i.industryblame##i.x i.ngoblame##i.x [pw = Weight] if q9==1
	qui margins x, dydx(hurt adjburden socprog) post
	est store c6`t'
    
	local t=`t'+1
	di "`x':"
	drop x
	}

  ** Table A6
  estout c5*, drop(*0b.*:) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 	 

  ** Table A7
  estout c6*, drop(*0b.*:) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 	 

  
* Combined messages

  g onlypos=(socprog==1) & (hurt==0 & adjburden==0)
  g onlyneg=((hurt==1|adjburden==1) & socprog==0)
  g mixed=((hurt==1|adjburden==1) & socprog==1)
  
  g MessageType=1*(onlypos==1)+2*(onlyneg==1)+3*(mixed==1)
  tab MessageType
 
  ** Figure A5 
  graph bar prog_app [pw=Weight] if q9==1, over(MessageType) scheme(s1mono) ytitle(Percent)
  
  
	
* Descriptive statistics 
  
  qui estpost su prog_app conf hurt adjb socp $X1 fte psj lang Wei q9
  esttab ., cells("count(fmt(0)) mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))")

  
* Additional plots - outcome distribution 

  ** Figure A1
  graph bar if q9==1, over(q3, label(angle(90))) scheme(s1mono) ytitle(Percent)
  
  ** Figure A2
  graph bar if q9==1, over(q6, relabel(1 "0" 11 "10") label(angle(0))) scheme(s1mono) ytitle(Percent)
  
	